package com.yupi.springbootinit.manager;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.HashMap;
import java.util.concurrent.TimeoutException;

public class MqInitMain {
    public static void main(String[] args) {
        try {
            String EXCHANGE_NAME = "code_exchange";
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            Connection connection = factory.newConnection();
            HashMap<String, Object> map = new HashMap<>();
            map.put("x-message-ttl",8000);
            Channel channel = connection.createChannel(); //队列1
            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT); //这是交换机，通用的

            String queueName = "code_queue";
            channel.queueDeclare(queueName,true,false,false,map);
            channel.queueBind(queueName, EXCHANGE_NAME, "my_routingKey");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
